﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LIB;
namespace LB5
{
    public partial class Form1 : Form
    {
        Creator[] creators = new Creator[3];
        Necklace Neck = new Necklace();
        public Form1()
        {
            InitializeComponent();
            
            creators[0] = new BrilliantCreator();
            creators[1] = new AdamantCreator();
            creators[2] = new AzurestoneCreator();
           
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int ww = -1, cc = -1;
           if (int.TryParse(textBox1.Text, out ww))
               ww = int.Parse(textBox1.Text);
           if (int.TryParse(textBox2.Text, out cc))
                cc = int.Parse(textBox2.Text);
           if (ww > 0 && cc > 0)
           {
               if (radioButton1.Checked)
                   Neck.add(creators[1].FactoryMethod(ww, cc));
               if (radioButton2.Checked)
                   Neck.add(creators[2].FactoryMethod(ww, cc));
               if (radioButton3.Checked)
                   Neck.add(creators[0].FactoryMethod(ww, cc));
           }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int num = 0;
            try
            {
                num = int.Parse(textBox3.Text);
                textBox3.Text = Neck.remove(num);
            }
            catch(Exception)
            {
                textBox3.Text = "Некорректный данные";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox5.Text = Neck.Get_sum().ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox6.Text = Neck.Get_weight().ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox4.Text = "";
            foreach(AbstactStone s in Neck.jewel)
            {
                textBox4.Text += s.GetType().Name + " " + s.weight.ToString() + " " + s.cost.ToString() + Environment.NewLine;
            }
        }
    }
}
